package com.HW;

import sun.reflect.generics.tree.Tree;

import java.util.*;

/**
 * @ClassName : TSupposeProQueue
 * @Author : kele
 * @Date: 2023/10/31 22:52
 * @Description :
 */
public class TSupposeProQueue {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String str = sc.nextLine();
        handle(str);

    }

    public static void handle(String str) {

        int[] arr = Arrays.stream(str.replace("(", "").replace(")", "").split(",")).mapToInt(Integer::parseInt).toArray();

        TreeMap<Integer, Queue<Integer>> map = new TreeMap<>(Comparator.reverseOrder());

        System.out.println(arr.length);

        for (int i = 0; i < arr.length / 2; i++) {

            Queue<Integer> queue = map.getOrDefault(arr[2 * i + 1], new LinkedList<>());
            if(!queue.contains(arr[2 * i])){
                queue.add(arr[2 * i]);
                map.put(arr[2 * i + 1], queue);
            }

        }

        StringBuilder builder = new StringBuilder();
        map.entrySet().forEach(x -> {
            while (!x.getValue().isEmpty()) {
                builder.append(x.getValue().poll()).append(",");
            }
        });

        System.out.println(builder.substring(0, builder.length() - 1));


    }
}
